const Schema = require('async-validator')

class Validator {
  constructor (rules) {
    this.validator = new Schema(rules)
  }
  validate (source, options = { first: true }) {
    const result = {}
    this.validator.validate(source, options, (errors, fields) => {
      result.errors = errors
      result.fields = fields
    })
    return result
  }
}

module.exports = Validator
